angular.controller(ꞌmain-loopꞌ)   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
nc 1
dl 0
loc 43
rs 8.8571
nop 8

3 Functions

Rating   Name   Duplication   Size   Complexity  
A ��) 0 5 1
A ��) 0 14 1
A ��) 0 12 3

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
'use strict';
2
3
angular
4
  .module('game')
5
  .controller('main-loop', ['$scope',
6
    '$interval',
7
    '$timeout',
8
    'savegame',
9
    'state',
10
    'data',
11
    'util',
12
    'reaction',
13
    function($scope, $interval, $timeout, savegame, state, data, util, reaction) {
14
      $scope.state = state;
15
      $scope.data = data;
16
      $scope.util = util;
17
18
      let self = this;
19
20
      self.update = function() {
21
        state.reactions = [];
22
        state.update(state.player);
23
        reaction.processReactions(state.reactions, state.player);
24
      };
25
26
      self.updateLoop = function() {
27
        self.update();
28
        let speed = 1000;
29
        if(state.fasterTicks){
30
          speed = 1;
31
          state.player.offline--;
32
          if(state.player.offline <= 0){
33
            state.fasterTicks = 0;
34
          }
35
        }
36
        $timeout(self.updateLoop, speed);
37
      };
38
39
      self.startup = function() {
40
        savegame.load();
41
        let elapsed = Math.floor(Date.now()/1000)-state.player.last_login;
42
        let total = util.calculateValue(data.global_upgrades.offline_time.power.base,
43
            data.global_upgrades.offline_time.power,
44
            state.player.global_upgrades.offline_time);
45
        // lets limit the offline elapsed time
46
        state.player.offline = Math.min(total, state.player.offline+elapsed);
47
48
        state.loading = false;
49
        // trigger the game loop
50
        $timeout(self.updateLoop, 1000);
51
        $interval(savegame.save, 10000);
52
      };
53
54
      $timeout(self.startup);
55
    }
56
  ]);
57